package com.gtq.uhome.service.serviceImpl;

import com.gtq.uhome.mapper.UserInfoMapper;

import com.gtq.uhome.pojo.Consignee;
import com.gtq.uhome.service.UserService;
import com.gtq.uhome.vo.OrderInfor;
import com.gtq.uhome.vo.UserInfo;
import com.gtq.uhome.vo.UserOrderInfor;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;
import sun.security.util.Length;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author ylhy
 * @Describe
 * @create 2020-07-30 18:50
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    UserInfoMapper userInfoMapper;

    /**
     * 查询所有用户信息
     * @return 用户信息
     */
    @Override
    public List<UserInfo> findAll() {
        List<UserInfo> all = userInfoMapper.findAll();
        return all;
    }

    /**
     *  模糊查询: 用户名/电话 状态 站点数字
     * @return
     */
    @Override
    public List<UserInfo> findByLike(Object keyWord, Object freezeStatus, Object siteName) {
        System.out.println(keyWord);
        System.out.println(freezeStatus);
        System.out.println(siteName);
        List<UserInfo> like = userInfoMapper.findByLike(keyWord,freezeStatus,siteName);
        /*------------------------*/
        for (UserInfo info : like) {
            System.out.println("用户信息"+info.getSiteName());
        }
        /*-----------------*/
        return like;
    }
    /**
     *  批量冻结   通过id冻结 需要冻结的表有  user表中的指定id的user数据
     * @param
     * @return
     */
    @Override
    public Integer freezeUser(ArrayList<Integer> id, String freezeStatus) {
        Integer lines = 0;
        for (Integer integer : id) {
            lines += userInfoMapper.freezeGroupByid(integer, freezeStatus);
        }
        return lines;
    }

    /**
     *  查询用户所有信息
     * @param userId
     * @return
     */
    @Override
    public UserInfo findUserInfo(Integer userId) {

        // 查询指定的一条用户信息
        UserInfo userInfo = userInfoMapper.findOneById(userId);

        // 查询用户收件人信息
        List<Consignee> userConsignee = userInfoMapper.findUserConsignee(userId);
        // 查询用户订单列表
        List<UserOrderInfor> userOrderInforList = userInfoMapper.OneUserOrderInfor(userId);

        for (UserOrderInfor userOrderInfor : userOrderInforList) {
            System.out.println("---------------------"+userOrderInfor+"--------------------");
        }
        // 填充用户收货人列表
        userInfo.setConsigneeList(userConsignee);

        // 查询用户订单列表
        userInfo.setUserOrderInforList(userOrderInforList);

        return userInfo;
    }

    /**
     * 查询用户一条物流单的信息
     * @return
     */
    @Override
    public List<OrderInfor> AllUserOrderInfor() {
        userInfoMapper.AllUserOrderInfor();
        return null;
    }


}
